package com.woniu.service.impl;

import com.woniu.entity.Orderform;
import com.woniu.entity.Orderitem;
import com.woniu.mapper.CategoryMapper;
import com.woniu.mapper.MyBatisUtil;
import com.woniu.mapper.OrderitemMapper;
import com.woniu.service.SelectOrder;
import org.apache.ibatis.session.SqlSession;

import java.text.SimpleDateFormat;
import java.util.Date;

public class SelectOrderImpl implements SelectOrder {
    @Override
    public Orderform selectOrder(String id) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        OrderitemMapper mapper = sqlSession.getMapper(OrderitemMapper.class);
        Orderitem orderitem = mapper.selectByiid(id);
        Orderform orderform = new Orderform();
        orderform.setOrderid(orderitem.getIid());
        orderform.setCount(orderitem.getCount());
        orderform.setUser(String.valueOf(orderitem.getOrders().getUsers().getUid()));
        orderform.setPrice(String.valueOf(orderitem.getSubtotal()));
        orderform.setCommodity(orderitem.getBook().getBname());
        orderform.setVariety(orderitem.getBook().getCategory().getCname());
        return orderform;
    }
}
